﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Main.GamePlay
{
    public class Fleet : Ship
    {
        public bool Fire = false;

        public Fleet()
        {

            DieTime = TimeSpan.FromSeconds(0.35);

            Initialize();
        }

        public override void Initialize()
        {
            Layer = 0.9f;
            HitsLeft = 3;
            Speed = FromPixelPerLoop(1.2f);
            Texture = shipTexture;
            Animated = false;
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            if (Status == ObjectStatus.Active)
            {

                if (LookRight)
                {
                    Velocity = new Vector2(FromPixelPerLoop(Speed * 0.03f), 0);
                }
                else
                {
                    Velocity = new Vector2((FromPixelPerLoop(Speed * 0.03f) * -1), 0);
                }

                if (Scale > 0.6f)
                {
                    if (Position.X > Window.ClientBounds.Width + 10)
                    {
                        Position = new Vector2(Window.ClientBounds.Width, Position.Y);
                        LookRight = !LookRight;
                        Layer = Layer - 0.1f;
                        Scale = Scale - 0.1f;
                    }

                    if (Position.X < -Texture.Width - 10)
                    {
                        Position = new Vector2(0, Position.Y);
                        LookRight = !LookRight;
                        Layer = Layer - 0.1f;
                        Scale = Scale - 0.1f;
                    }
                }



                if (Selected)
                {
                    Color = Color.Yellow;
                }
                else
                {
                    Color = Color.White;
                }

                base.Update(gameTime);//este "base" tá chamando o update da classe superior (ship)

            }

            
        }

        #region Static Region

        public static Texture2D shipTexture;

        public static Fleet GenerateShip(Viewport viewport, Vector2 P1, Vector2 P2, Vector2 P3, Vector2 P4)
        {
            Random r = new Random();
            Fleet e = new Fleet();

            Vector2 line1Position;
            Vector2 line2Position;
            Vector2 line3Position;
            Vector2 line4Position;

            line1Position = P1;
            line2Position = P2;
            line3Position = P3;
            line4Position = P4;

            Random RandomLine = new Random();
            int lineSpawn = 0;

            lineSpawn = RandomLine.Next(1, 5);

            switch (lineSpawn)
            {
                case 1:
                    e.Position = new Vector2(0, line1Position.Y - (e.Texture.Height/2));
                    break;

                case 2:
                    e.Position = new Vector2(0, line2Position.Y - (e.Texture.Height / 2));
                    break;

                case 3:
                    e.Position = new Vector2(0, line3Position.Y - (e.Texture.Height / 2));
                    break;

                case 4:
                    e.Position = new Vector2(0, line4Position.Y - (e.Texture.Height / 2));
                    break;

                case 5:
                    lineSpawn = RandomLine.Next(1, 5); ;
                    break;
            }

            return e;

        }// generate new Ship in random guide line

        #endregion
    }
}